package com.csweimei.rentmanagementtreasure;

import android.app.Application;
import android.content.Context;

import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.gtdev5.geetolsdk.mylibrary.contants.Contants;
import com.gtdev5.geetolsdk.mylibrary.initialization.GeetolSDK;
import com.gtdev5.geetolsdk.mylibrary.util.SpUtils;
//import com.mob.MobSDK;
import com.mob.MobSDK;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;

import me.goldze.mvvmhabit.base.BaseApplication;
import me.goldze.mvvmhabit.crash.CaocConfig;
import me.goldze.mvvmhabit.utils.KLog;

public class MyApplication extends BaseApplication {


    public static Context context;
    private static MyApplication application;

    public static MyApplication getInstance() {
        if (application == null) {
            application = new MyApplication();
        }
        return application;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        BaseApplication.setApplication(this);
        context = getApplicationContext();
        //初始化GTSDK
        GeetolSDK.init(this);
        SpUtils.getInstance().putString(Contants.COMMON_URL, "http://api.csweimei.cn/app/");

        UMConfigure.preInit(context, AppConfig.UMENG_KEY,"Umeng");

        //是否开启日志打印
        KLog.init(true);
        //配置全局异常崩溃操作
        CaocConfig.Builder.create()
                .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //背景模式,开启沉浸式
                .enabled(false) //是否启动全局异常捕获
                .showErrorDetails(false) //是否显示错误详细信息
                .showRestartButton(false) //是否显示重启按钮
                .trackActivities(false) //是否跟踪Activity
                .minTimeBetweenCrashesMs(2000) //崩溃的间隔时间(毫秒)
                .errorDrawable(R.mipmap.logo) //错误图标
//                .restartActivity(LoginActivity.class) //重新启动后的activity
                //.errorActivity(YourCustomErrorActivity.class) //崩溃后的错误activity
                //.eventListener(new YourCustomEventListener()) //崩溃后的错误监听
                .apply();

    }


    private void initMob(Context context){
        MobSDK.init(context);
        MobSDK.submitPolicyGrantResult(true);
    }

    public void initUmeng(Context splashActivity) {

        /**
         * 注意: 即使您已经在AndroidManifest.xml中配置过appkey和channel值，也需要在App代码中调
         *
         * 用初始化接口（如需要使用AndroidManifest.xml中配置好的appkey和channel值，
         * UMConfigure.init调用中appkey和channel参数请置为null）。
         */
        UMConfigure.init(context,AppConfig.UMENG_KEY,"Umeng",UMConfigure.DEVICE_TYPE_PHONE,"");
        // 选用AUTO页面采集模式
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
        initMob(splashActivity);

    }

}
